package sqba.jamper.util;

import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

public class EncOptManager {
	
	static JRadioButton CBox[];
	static String BName[] = {"TV", "Labtop", "PMP", "Mobile"};
	
	public EncOptManager(JPanel pan){
		ButtonGroup group = new ButtonGroup();
		CBox = new JRadioButton[BName.length];
		for( int i = 0 ; i < CBox.length ; i++ ){
			CBox[i] = new JRadioButton(BName[i]);
			pan.add(CBox[i]);
			group.add(CBox[i]);
		}
	}
	
	static public int getValue(){
		int re = 0;
		for( int i = 0 ; i < CBox.length ; i++ )
			re = re*2 + ((CBox[i].isSelected())?1:0);
		return re;
	}
	
	static public void setValue(int v){
		for( int i = CBox.length-1 ; i>= 0 ; i--, v/=2 )
			CBox[i].setSelected((v&1)==1);
	}
	
	   /**
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
     */
    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("SimpleTableDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Create and set up the content pane.
        JPanel newContentPane = new JPanel();
        EncOptManager eom = new EncOptManager( newContentPane );
        newContentPane.setOpaque(true); //content panes must be opaque
        frame.setContentPane(newContentPane);
        eom.setValue(0);
        //Display the window.
        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
	
}
